<template>
  <div class="Allpadding">
      <div class="logo">
          <img src="@/assets/image/logo.png" alt="">     
      </div>
      <p class="font_p">一个账号玩转所有服务</p>
        <div class="loginFrom">
                 <van-form @submit="onSubmit" res='form'>
                <van-field
                v-model="form.phone"
                name="phone"
                placeholder="请输入电话号码"
                :left-icon="'phone-o'"
                :rules="[{ required: true, message: '请填写电话号码' },
                {
                        pattern:reg.phone,
                        message:'请输入正确的手机号'
                }
                ]"
                />

                <van-field
                v-model="form.password"
                :type="type"
                name="password"
                placeholder="密码"
                :left-icon="'shield-o'"
                :right-icon="type=='password'?'closed-eye':'eye-o'"
                @click-right-icon="changeType"
                :rules="[{ required: true, message: '6-16的数字字母组合' },
                {
                    pattern:reg.pwd,message:'请输入6-16的数字字母组合'
                },
                ]"
                />

                <div style="margin: 20px;">
                <van-button  block type="info" native-type="submit" style="font-size:20px; border-radius: 20px;">登 录</van-button>
                </div>
                <div class="footer">
                    <div>从这里出发，开启新世界  <span style="font-size:16px;color: #fb7299;margin-left:10px" @click="gotoregister">立即注册</span></div>
                    <p>客服电话:<span style="color:#fb7299;margin-top:10px">18671643106</span></p>
                </div>
            </van-form>
        </div>
        <!-- 找回密码 -->
       <div class="forgetpass">
        <p @click="gotoforgetpass">找回密码</p>
       </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
     form:{},
       type:"password"
    };
  },
  methods: {
      //点击跳转找回密码
      gotoforgetpass(){
          this.$router.push({
              name:'forgetpass'
          })
      },
   async onSubmit(value){
        // 登录 
        console.log(value);
        let res = await this.$ajax.findUser(value)
        console.log(res);
        if(res.length>0){
            // 用户信息存储
            // vuex 
            console.log(res[0]);
            this.changeUserInfo(res[0]);    
            console.log(this.userInfo);
            this.$router.push({
                name:'home'
            })
        }else{
            this.$toast("登录失败,用户名或者密码错误")
        }
    },
    changeType(){
    this.type = this.type =='password' ?'text':'password'
    }, 
    //点击跳转注册
    gotoregister(){
       this.$router.push({
             name:'register'
       })                 
    },
  },
  mounted() {
      console.log(this.userInfo);
  },
};
</script>

<style>
.logo{
    margin-top: 10px;
    width: 150px;
    height: 100px;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    height: 50px;
}
.font_p{
     font-size: 16px;
    text-align: center;
}
.logo img{
    width: 100%;
}
.loginFrom{
    margin-top: 16px;
}
 .van-field__left-icon .van-icon, 
 .van-field__right-icon .van-icon{
  font-size: 30px !important;
  margin-right: 20px;
}
.footer{
    position: absolute;
    bottom:0px;
    width: 100%;
    height: 100px;
    text-align: center;
   
}
.forgetpass{
  width: 100%;
  font-size: 16px;
  text-align: right;
  padding-right: 10px;
  margin-top: 10px;
  color: #fb7299;
}
.van-button--info{
    background: #fb7299;
    border: #fb7299;
}

</style>